$(document).ready(function(){

	$('#select_game').change(function() {
	    url = CONTEXT_PATH + "/db/bak/game?gameId=" + $("#select_game").val();
	    window.location.href = url;
	});

});

String.prototype.replaceAll  = function(s1,s2){     
    return this.replace(new RegExp(s1,"gm"),s2);     
}

function manualDbBak(serverId) {
	var result = document.getElementById('state' + serverId).innerText;

	if (result == '成功') {
		alert('定时任务备份成功，无需手动备份');
	} else {
		var index = layer.load(1, {
			  shade: [0.1,'#fff'] //0.1透明度的白色背景
		});
		
		$.wajax({
		    type: "POST",
		    url: CONTEXT_PATH + '/db/bak/manualBak?serverId=' + serverId,
		    success: function(result) {
		    	layer.close(index);
		    	var msg = result.msg;
		    	if (result.code == RESULT_SUCCESS) {
		    		msg = msg + "<br>" + result.data;
		    	}
		    	
		    	layer.alert(msg, {icon: 6});
		    }
		});
	}
}

function manualDbBakRemote(ip, serverId) {
	var result = document.getElementById('state' + serverId).innerText;

	if (result == '成功') {
		alert('定时任务备份成功，无需手动备份');
	} else {
		// host_init对应Common.DB_BAK_REMOTE_PREFIX
		parent.makeGlobalLayer('正在远程备份：' + ip, 'bak_remote_' + ip.replaceAll('\\.', '_'));
		
		$.wajax({
		    type: "POST",
		    url: CONTEXT_PATH + '/db/bak/manualBakRemote?serverId=' + serverId,
		    success: function(result) {
		    	
		    }
		});
	}
}